package com.sitanyun.merchant.guide.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.bean.RankBean;
import com.sitanyun.merchant.guide.weiht.ToolsUtil;

import java.util.List;

/**
 * Created by jzl
 * on 2022/3/26.
 * 员工排行榜
 */
public class RankBaseAdapter extends BaseAdapter {
    private Context context;
    private List<RankBean.DataBean>    ranklist;

    public RankBaseAdapter(Context context, List<RankBean.DataBean> ranklist) {
        this.context = context;
        this.ranklist = ranklist;
    }

    @Override
    public int getCount() {
        return ranklist.size();
    }

    @Override
    public Object getItem(int position) {
        return ranklist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.rank_item, null);
        TextView uname = convertView.findViewById(R.id.tv_rankname);
        ProgressBar progressBar = convertView.findViewById(R.id.pg_bar);
        TextView ranknum = convertView.findViewById(R.id.tv_ranknum);
        if (ranklist.size()==0){

        }else {
            //分享次数1,被浏览次数2,互动留言次数3,要求回电次数4,同屏讲解时长5
            switch (ranklist.get(position).getQueryType()) {
                case 1:
                    uname.setText(ranklist.get(position).getStaffName());
                    ranknum.setText(ranklist.get(position).getShare() + "次");

                    int max = ranklist.get(0).getShare();
                    if (max < ranklist.get(position).getShare())
                        max = ranklist.get(position).getShare();
                    progressBar.setMax(max);
                    progressBar.setProgress(ranklist.get(position).getShare());

                    Log.e("TAG",progressBar.getMax()+"getShare");
                    break;
                case 2:
                    uname.setText(ranklist.get(position).getStaffName());
                    ranknum.setText(ranklist.get(position).getBrowse() + "次");
                    int maxBrowse = ranklist.get(0).getBrowse();
                    if (maxBrowse < ranklist.get(position).getBrowse())
                        maxBrowse = ranklist.get(position).getBrowse();
                    progressBar.setMax(maxBrowse);
                    progressBar.setProgress(ranklist.get(position).getBrowse());

                    Log.e("TAG",progressBar.getMax()+"getBrowse");
                    break;
                case 3:
                    uname.setText(ranklist.get(position).getStaffName());
                    ranknum.setText(ranklist.get(position).getMessage() + "次");
                    int maxmessage = ranklist.get(0).getMessage();
                    if (maxmessage < ranklist.get(position).getMessage())
                        maxmessage = ranklist.get(position).getMessage();
                    progressBar.setMax(maxmessage);
                    progressBar.setProgress(ranklist.get(position).getMessage());

                    Log.e("TAG",progressBar.getMax()+"getMessage");
                    break;
                case 4:
                    uname.setText(ranklist.get(position).getStaffName());
                    ranknum.setText(ranklist.get(position).getCalls() + "次");
                    int maxcall = ranklist.get(0).getCalls();
                    if (maxcall < ranklist.get(position).getCalls())
                        maxcall = ranklist.get(position).getCalls();
                    progressBar.setMax(maxcall);
                    progressBar.setProgress(ranklist.get(position).getCalls());

                    Log.e("TAG",progressBar.getMax()+"getCalls");
                    break;
                case 5:
                    uname.setText(ranklist.get(position).getStaffName());
                    //  ranknum.setText(ranklist.get(position).getMeetingTime() + "");
                    //ToolsUtil. timeToString(ranklist.get(position).getMeetingTime()*1000);
                    ranknum.setText( ToolsUtil. timeConversion(ranklist.get(position).getMeetingTime()));


                    int maxtime = ranklist.get(0).getMeetingTime();
                    if (maxtime < ranklist.get(position).getMeetingTime())
                        maxtime = ranklist.get(position).getMeetingTime();
                    progressBar.setMax(maxtime);
                    progressBar.setProgress(ranklist.get(position).getMeetingTime());
                    Log.e("TAG",progressBar.getMax()+"getMeetingTime");
                    break;
                case 6:
                    uname.setText(ranklist.get(position).getStaffName());
                    ranknum.setText(ranklist.get(position).getInterpret() + "次");
                    int maxinter = ranklist.get(0).getInterpret();
                    if (maxinter < ranklist.get(position).getInterpret())
                        maxinter = ranklist.get(position).getInterpret();
                    progressBar.setMax(maxinter);
                    progressBar.setProgress(ranklist.get(position).getInterpret());

                    Log.e("TAG",progressBar.getMax()+"getInterpret");
                    break;
            }
        }

            return convertView;
        }

}
